const path = require('path');

const htmlWebpackPlugin = require('html-webpack-plugin')

const VueLoaderPlugin = require('vue-loader/lib/plugin')


module.exports = {
    entry: path.join(__dirname, 'src/main.js'),
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'main.js'
    },
    plugins: [
        new htmlWebpackPlugin({
            template: path.join(__dirname, 'src/index.html'),
            filename: 'index.html'
        }),
        new VueLoaderPlugin()
    ],
    module: {
        rules: [{
                test: /\.css$/,
                use: ['style-loader', 'css-loader']
            }, {
                test: /\.less$/,
                use: ['style-loader', 'css-loader', 'less-loader']
            },
            {
                test: /\.vue$/,
                loader: 'vue-loader'
            },
            {
                test: /\.(jpg|png|gif|bmp|svg)$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        esModule: false, // 这里设置为false
                        name: '[hash:8]-[name].[ext]',
                        limit: 10240
                    }
                }
            },
            {
                test: /\.(woff|woff2|eot|ttf)$/,
                use: 'url-loader?limit=1000&name=[hash:8]-[name].[ext]'
            },
            {
                test: /\.js$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-env'],
                        plugins: [
                            ["import", {
                                "libraryName": "vant",
                                "libraryDirectory": "es",
                                "style": true
                            }]
                        ]
                    }
                }
            }
        ]
    },
    resolve: {
        alias: {
            "@pages": path.join(__dirname, 'src/pages'),
            "@components": path.join(__dirname, 'src/components'),
            "@api":path.join(__dirname,'src/api')
        }
    },
    devServer: {
        open:true,
        // 配置代理
        proxy: {
            // "/v1/restserver/ting": {
            //     target: "http://tingapi.ting.baidu.com",
            //     changeOrigin: true
            // },
            // "/api": {
            //     target: "http://59.111.92.205:8088",
            //     changeOrigin: true
            // },
            "/api": {
                // http://tingapi.ting.baidu.com/resful/v1/restserver/ting...
                target: "http://tingapi.ting.baidu.com",
                changeOrigin: true,
                // 通过这个属性配置，去掉/resful
                // http://tingapi.ting.baidu.com/v1/restserver/ting...
                pathRewrite: {
                    '^/api': ''
                }
            }
        }
    }
}